package com.fare.taluo.fetl.domain.repository.history.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.fare.taluo.fetl.domain.repository.history.IDoublePlaneInfoHistoryRepository;
import com.fare.taluo.helper.HbaseCustom;
import com.fare.taluo.util.DateUtils;
import com.fare.taluo.vo.core.PlaneInfo;

@Repository
public class DoublePlaneInfoHistoryRepository implements
		IDoublePlaneInfoHistoryRepository {

	@Override
	public List<PlaneInfo> find(Date crawlDate, String hbaseKey,
			String fromCode, String toCode, Date flightDate,
			Date returnFlightDate) throws Exception {
		//hbase表rowkey= 00002 CAN AKL 20140402 20140409 20140416 000CZ305 00000000 00000000
		//渠道hbasekey[5位]出发城市三字码[3位]到达城市三字码[3位]抓取时间[8位yyyyMMdd]
		//去程航班时间[8位yyyyMMdd]返程航班时间[8位yyyyMMdd]航班号[8位，不足则左侧补0]
		//中转航班号1[8位，不足则左侧补0]中转航班号2[8位，不足则左侧补0]
		String startRowKey = String.format("%1s%2s%3s%4s%5s%6s%7s%7s%7s", hbaseKey,
				fromCode, toCode, DateUtils.formatTime(crawlDate, "yyyyMMdd"),
				DateUtils.formatTime(flightDate, "yyyyMMdd"),
				DateUtils.formatTime(returnFlightDate, "yyyyMMdd"),
				"00000000");
		String endRowKey = String.format("%1s%2s%3s%4s%5s%6s%7s%7s%7s", hbaseKey,
				fromCode, toCode, DateUtils.formatTime(crawlDate, "yyyyMMdd"),
				DateUtils.formatTime(flightDate, "yyyyMMdd"),
				DateUtils.formatTime(returnFlightDate, "yyyyMMdd"),
				"ZZZZZZZZ");
		return HbaseCustom.findByConditionsToPlaneInfo(
						HbaseCustom.LP_FLIGHT_HISTORY_DOUBLE, startRowKey, endRowKey);
	}

	@Override
	public List<PlaneInfo> find(Date crawlDate, String hbaseKey,
			String fromCode, String toCode, Date flightDate,
			String flightNo, Date returnFlightDate)throws Exception {
		//hbase表rowkey= 00002 CAN AKL 20140402 20140409 20140416 000CZ305 00000000 00000000
		//渠道hbasekey[5位]出发城市三字码[3位]到达城市三字码[3位]抓取时间[8位yyyyMMdd]
		//去程航班时间[8位yyyyMMdd]返程航班时间[8位yyyyMMdd]航班号[8位，不足则左侧补0]
		//中转航班号1[8位，不足则左侧补0]中转航班号2[8位，不足则左侧补0]
		String startRowKey = String.format("%1s%2s%3s%4s%5s%6s%7s%8s%8s", hbaseKey,
				fromCode, toCode, DateUtils.formatTime(crawlDate, "yyyyMMdd"),
				DateUtils.formatTime(flightDate, "yyyyMMdd"),
				DateUtils.formatTime(returnFlightDate, "yyyyMMdd"),
				flightNo,"00000000");
		String endRowKey = String.format("%1s%2s%3s%4s%5s%6s%7s%8s%8s", hbaseKey,
				fromCode, toCode, DateUtils.formatTime(crawlDate, "yyyyMMdd"),
				DateUtils.formatTime(flightDate, "yyyyMMdd"),
				DateUtils.formatTime(returnFlightDate, "yyyyMMdd"),
				flightNo, "ZZZZZZZZ");
		return HbaseCustom.findByConditionsToPlaneInfo(
						HbaseCustom.LP_FLIGHT_HISTORY_DOUBLE, startRowKey, endRowKey);
	}

}
